package com.example.search.controller;


import com.common.to.es.SkuEsUpTo;
import com.common.utils.R;
import com.common.valid.CodeEnume;
import com.example.search.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/search")
@Slf4j
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping("/up")
    public R up(@RequestBody List<SkuEsUpTo> skuList) {
        Boolean success = null;
        try {
            success = productService.productUp(skuList);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (success == null || !success) {
            return R.error(CodeEnume.PRODUCT_UP_EXCEPTION.getCode(), CodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
        }
        return R.ok();
    }
}
